package com.qu.waibao.my.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qu.waibao.AppConfig;
import com.qu.waibao.R;
import com.qu.waibao.base.BaseActivity;
import com.qu.waibao.interf.XnetCallBack;
import com.qu.waibao.network.ActionUtil;
import com.qu.waibao.network.NetManager;
import com.qu.waibao.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

import static com.qu.waibao.R.id.sweep_arrow;
import static com.qu.waibao.R.id.tv_submit;

public class TixianActivity extends BaseActivity implements View.OnClickListener{
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.ll_zhifubao_show)
    LinearLayout ll_zhifubao_show;
    @BindView(R.id.ll_bank_show)
    LinearLayout ll_bank_show;
    @BindView(R.id.iv_publish)
    ImageView iv_publish;
    @BindView(R.id.et_account)
    EditText et_account;
    @BindView(R.id.et_name)
    EditText et_name;
    @BindView(R.id.et_bank_area)
    EditText et_bank_area;
    @BindView(R.id.et_card)
    EditText et_card;
    @BindView(R.id.et_money)
    EditText et_money;
    @BindView(R.id.tv_yu_money)
    TextView tv_yu_money;
    @BindView(R.id.cb_zhifubao)
    TextView cb_zhifubao;
    @BindView(R.id.cb_bank)
    TextView cb_bank;
    private String account_type = "支付宝";
    private String total_all = "";
    @Override
    protected boolean initBundle(Bundle bundle) {
        if(bundle != null){
            total_all = bundle.getString("total_all","");
        }
        return super.initBundle(bundle);
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_tixian;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        tv_title.setText("提现");
        iv_publish.setVisibility(View.GONE);
        tv_yu_money.setText("剩余可提现金额¥"+total_all);
        cb_zhifubao.setSelected(true);
    }

    @Override
    protected void initData() {
        super.initData();
    }
    @OnClick({R.id.ll_back,R.id.tv_submit,R.id.tv_all_tixian,R.id.iv_delete,R.id.ll_bank,R.id.ll_zhifubao})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_back:
                finish();
                 break;
            case R.id.tv_all_tixian:
                et_money.setText(total_all);
                /*if(account_type.equals("支付宝")){
                    String account = et_account.getText().toString();
                    String name = et_name.getText().toString();
                    if(TextUtils.isEmpty(account)){
                        ToastUtil.show(this,"请输入支付宝帐号");
                        return;
                    }else if(TextUtils.isEmpty(name)){
                        ToastUtil.show(this,"请输入支付宝帐号名");
                        return;
                    }
                    tixian(total_all,account,name);
                }else if(account_type.equals("银行卡")){
                    String account = et_card.getText().toString();
                    String name = et_bank_area.getText().toString();
                    if(TextUtils.isEmpty(account)){
                        ToastUtil.show(this,"请输入银行卡号");
                        return;
                    }else if(TextUtils.isEmpty(name)){
                        ToastUtil.show(this,"请输入所在银行");
                        return;
                    }
                    tixian(total_all,account,name);
                }*/
                break;
            case R.id.iv_delete:
                et_money.setText("");

            case R.id.ll_bank:
                ll_zhifubao_show.setVisibility(View.GONE);
                ll_bank_show.setVisibility(View.VISIBLE);
                cb_zhifubao.setTextColor(Color.parseColor("#333333"));
                cb_bank.setTextColor(Color.parseColor("#67b8f2"));
                cb_zhifubao.setSelected(false);
                cb_bank.setSelected(true);
                account_type = "银行卡";
                break;
            case R.id.ll_zhifubao:
                ll_zhifubao_show.setVisibility(View.VISIBLE);
                ll_bank_show.setVisibility(View.GONE);
                cb_zhifubao.setTextColor(Color.parseColor("#67b8f2"));
                cb_bank.setTextColor(Color.parseColor("#333333"));
                cb_zhifubao.setSelected(true);
                cb_bank.setSelected(false);
                account_type = "支付宝";
                break;
            case R.id.tv_submit:
                if(account_type.equals("支付宝")){
                    String account = et_account.getText().toString();
                    String name = et_name.getText().toString();
                    String monet = et_money.getText().toString();
                    if(TextUtils.isEmpty(account)){
                        ToastUtil.show(this,"请输入支付宝帐号");
                        return;
                    }else if(TextUtils.isEmpty(name)){
                        ToastUtil.show(this,"请输入支付宝帐号名");
                        return;
                    }else if(TextUtils.isEmpty(monet)){
                        ToastUtil.show(this,"请输入提现金额");
                        return;
                    }
                    tixian(monet,account,name);
                }else if(account_type.equals("银行卡")){
                    String account = et_card.getText().toString();
                    String name = et_bank_area.getText().toString();
                    String monet = et_money.getText().toString();
                    if(TextUtils.isEmpty(account)){
                        ToastUtil.show(this,"请输入银行卡号");
                        return;
                    }else if(TextUtils.isEmpty(name)){
                        ToastUtil.show(this,"请输入所在银行");
                        return;
                    }else if(TextUtils.isEmpty(monet)){
                        ToastUtil.show(this,"请输入提现金额");
                        return;
                    }
                    tixian(monet,account,name);
                }
                break;
        }
    }

    public void tixian(String optmoney,String account_code,String account_main){
        Map<String,String> map = new HashMap<>();
        map.put("action", ActionUtil.tixian_set);
        map.put("userid", AppConfig.getString("userid"));
        map.put("optmoney",optmoney);
        map.put("account_type",account_type);
        map.put("account_code",account_code);
        map.put("account_main",account_main);
        NetManager.getInstance().request(this, map, true, new XnetCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                 ToastUtil.show(TixianActivity.this,msg);
                 finish();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
